// app.js
App({
  globalData: {
    userInfo: null,
    isAdmin: false,
    currentUser: null
  },
  
  onLaunch() {
    console.log('油乐油小程序启动')
    // 检查登录状态
    this.checkLoginStatus()
  },

  checkLoginStatus() {
    const userInfo = wx.getStorageSync('userInfo')
    if (userInfo) {
      this.globalData.userInfo = userInfo
      this.globalData.isAdmin = userInfo.role === 'admin'
      this.globalData.currentUser = userInfo
    }
  },

  // 登录方法
  login(userInfo) {
    this.globalData.userInfo = userInfo
    this.globalData.isAdmin = userInfo.role === 'admin'
    this.globalData.currentUser = userInfo
    wx.setStorageSync('userInfo', userInfo)
  },

  // 退出登录
  logout() {
    this.globalData.userInfo = null
    this.globalData.isAdmin = false
    this.globalData.currentUser = null
    wx.removeStorageSync('userInfo')
  }
})